package com.ruoyi.web.controller.biz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.biz.request.ControlSwitchRequest;
import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizCatenarySwitch;
import com.ruoyi.biz.service.IBizCatenarySwitchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接触网开关数据管理Controller
 * 
 * @author cc
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/system/catenary_switch")
public class BizCatenarySwitchController extends BaseController
{
    @Autowired
    private IBizCatenarySwitchService bizCatenarySwitchService;

    /**
     * 查询接触网开关数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCatenarySwitch bizCatenarySwitch)
    {
        startPage();
        List<BizCatenarySwitch> list = bizCatenarySwitchService.selectBizCatenarySwitchList(bizCatenarySwitch);
        return getDataTable(list);
    }

    /**
     * 导出接触网开关数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:export')")
    @Log(title = "接触网开关数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCatenarySwitch bizCatenarySwitch)
    {
        List<BizCatenarySwitch> list = bizCatenarySwitchService.selectBizCatenarySwitchList(bizCatenarySwitch);
        ExcelUtil<BizCatenarySwitch> util = new ExcelUtil<BizCatenarySwitch>(BizCatenarySwitch.class);
        util.exportExcel(response, list, "接触网开关数据管理数据");
    }

    /**
     * 获取接触网开关数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCatenarySwitchService.selectBizCatenarySwitchById(id));
    }

    /**
     * 新增接触网开关数据管理
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:add')")
    @Log(title = "接触网开关数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCatenarySwitch bizCatenarySwitch)
    {
        return toAjax(bizCatenarySwitchService.insertBizCatenarySwitch(bizCatenarySwitch));
    }

    /**
     * 修改接触网开关数据管理
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:edit')")
    @Log(title = "接触网开关数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCatenarySwitch bizCatenarySwitch)
    {
        return toAjax(bizCatenarySwitchService.updateBizCatenarySwitch(bizCatenarySwitch));
    }

    /**
     * 删除接触网开关数据管理
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:remove')")
    @Log(title = "接触网开关数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCatenarySwitchService.deleteBizCatenarySwitchByIds(ids));
    }

    /**
     * 通过图纸id获取接触网开关数据
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:query')")
    @GetMapping(value = "/getByDrawingId/{drawingId}")
    public AjaxResult getByDrawingId(@PathVariable("drawingId") Long drawingId)
    {
        return success( bizCatenarySwitchService.getByDrawingId(drawingId));
    }
    /**
     * 通过图纸id获取接触网开关和线路
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:query')")
    @GetMapping(value = "/getSwitchAndLinesByDrawingId/{drawingId}")
    public AjaxResult getSwitchAndLinesByDrawingId(@PathVariable("drawingId") Long drawingId){
        return success( bizCatenarySwitchService.getSwitchAndLinesByDrawingId(drawingId));
    }

    /**
     * 通过图纸id获取接触网开关和线路
     */
    @PreAuthorize("@ss.hasPermi('system:catenary_switch:edit')")
    @PostMapping(value = "/control")
    public AjaxResult control(@RequestBody ControlSwitchRequest request){
        LoginUser loginUser = getLoginUser();
        return success( bizCatenarySwitchService.control(request,loginUser));
    }
}
